IF exists(SELECT * FROM dbo.sysobjects WHERE name='WEB_schoolverloopHistoriek' AND xtype='P') 
BEGIN
	DROP PROCEDURE WEB_schoolverloopHistoriek
END
GO

CREATE   procedure WEB_schoolverloopHistoriek(@hoofdNr int,@iNr char(7))
as
set nocount on
select @hoofdNr,1,'<historiek>'
union
select @hoofdNr,convert(bigint,datum),'<klas naam="' + isNull(klas,'') + '"><datum>' + isNull(convert(varchar(15),datum,103),'') + '</datum>' +
'<jaar>' + isNull(schooljaar,'') + '</jaar>' +
'<school schoolNr="' + isNull(h.schoolnummer,'') + '" stamNr="' + 
	isNull(stamboekNr,'') + '">' + isNull(benaming,'') + '</school></klas>'
from studieGegevens..historiek as h
	left join studieGegevens..scholen as s
	on h.schoolNummer = s.schoolNummer
where inschrijvingsNr = @iNr
union
select @hoofdNr,99999999,'</historiek>'